473,543 Members | 4,407 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to convert HTML special characters to the real characters with a Java script

I read data (e.g. äöüÄÖÜçéàè"') from my MySQL database which I'd like to
show in an input box.

<?php
$mysql_data = "äöüÄÖÜçéàè\"'" ;
$html_data = addslashes(html entities($mysql _data, ENT_QUOTES));

echo "<script type = 'text/javascript'>";
echo "function set_old_data() {";
echo "my_form.input1 .value = var_old_data;";
echo "}";
echo "var_old_da ta = '" . $html_data . "';";
echo "</script>";

echo "<body>";
echo "<form name = 'my_form' action = '' method = 'post' accept-charset
= 'iso-8859-1'>";
echo "<input type = 'text' name = 'input1' value = '" . $html_data .
"'>";
echo "<input type = 'button' value = 'Old Data' onClick =
'set_old_data() '>";
echo "</form>";
echo "</body>";
?>

The command
echo "<input type = 'text' name = 'input1' value = '" . $html_data . "'>";
shows my data äöüÄÖÜçéàè"' in the input box perfect.

But if I click on the button 'Old Data' the Java script function
'set_old_data' shows in the input box
&auml;&ouml;&uu ml;&Auml;&Ouml; &Uuml;&ccedil;& eacute;&agrave; &egrave;&quo t;'
instead of
äöüÄÖÜçéàè"'

Therefore I need a Java script function with translates
&auml;&ouml;&uu ml;&Auml;&Ouml; &Uuml;&ccedil;& eacute;&agrave; &egrave;&quo t;'
to
äöüÄÖÜçéàè"'

In PHP I could do that with the function
html_entity_dec ode()

But how can I do it with a Java script?
Stefan

PS: html_entity_dec ode() is the opposite of htmlentities(). It converts all
HTML entities to their applicable characters from string.
Mar 21 '06 #1
6 14815
Stefan Mueller wrote:
I read data (e.g. äöüÄÖÜçéàè"') from my MySQL database which I'd like to
show in an input box.

<?php
$mysql_data = "äöüÄÖÜçéàè\"'" ;
$html_data = addslashes(html entities($mysql _data, ENT_QUOTES));

echo "<script type = 'text/javascript'>";
echo "function set_old_data() {";
echo "my_form.input1 .value = var_old_data;";
echo "}";
echo "var_old_da ta = '" . $html_data . "';";
echo "</script>";

echo "<body>";
echo "<form name = 'my_form' action = '' method = 'post' accept-charset
= 'iso-8859-1'>";
echo "<input type = 'text' name = 'input1' value = '" . $html_data .
"'>";
echo "<input type = 'button' value = 'Old Data' onClick =
'set_old_data() '>";
echo "</form>";
echo "</body>";
?>

The command
echo "<input type = 'text' name = 'input1' value = '" . $html_data . "'>";
shows my data äöüÄÖÜçéàè"' in the input box perfect.

But if I click on the button 'Old Data' the Java script function
'set_old_data' shows in the input box
&auml;&ouml;&uu ml;&Auml;&Ouml; &Uuml;&ccedil;& eacute;&agrave; &egrave;&quo t;'
instead of
äöüÄÖÜçéàè"'

Therefore I need a Java script function with translates
&auml;&ouml;&uu ml;&Auml;&Ouml; &Uuml;&ccedil;& eacute;&agrave; &egrave;&quo t;'
to
äöüÄÖÜçéàè"'

In PHP I could do that with the function
html_entity_dec ode()

But how can I do it with a Java script?
Stefan

PS: html_entity_dec ode() is the opposite of htmlentities(). It converts all
HTML entities to their applicable characters from string.


Uh, maybe ask in a Javascript newsgroup?

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Mar 21 '06 #2
Stefan Mueller wrote:
Therefore I need a Java script function with translates
&auml;&ouml;&uu ml;&Auml;&Ouml; &Uuml;&ccedil;& eacute;&agrave; &egrave;&quo t;'
to
äöüÄÖÜçéàè"'

In PHP I could do that with the function
html_entity_dec ode()

But how can I do it with a Java script?
Stefan

PS: html_entity_dec ode() is the opposite of htmlentities(). It converts all
HTML entities to their applicable characters from string.


This relies on IE extensions but you can it's possible to make it
standard compatible.

function html_entity_dec ode(s) {
var span = document.create Element('SPAN') ;
span.innerHTML = s;
return span.innerText;
}

Mar 22 '06 #3
On a second thought, it's probably easier if you just dump the text
into a hidden field.

Mar 22 '06 #4
> function html_entity_dec ode(s) {
var span = document.create Element('SPAN') ;
span.innerHTML = s;
return span.innerText;
}


Yea, this is exactly what I'm looking for. But like you mentioned it only
works for IE and not for Mozilla, Opera, Safari, ...

Stefan

Mar 22 '06 #5

Stefan Mueller wrote:
function html_entity_dec ode(s) {
var span = document.create Element('SPAN') ;
span.innerHTML = s;
return span.innerText;
}


Yea, this is exactly what I'm looking for. But like you mentioned it only
works for IE and not for Mozilla, Opera, Safari, ...

Stefan


Most browsers support innerHTML, even though it's non-standard, because
it's so convinent. innerText is supported only by IE as far as I know.
In the other browsers, you can get the plain text from
span.firstChild .nodeValue.

As I said in the follow-up, it's easier to store the original value in
a hidden field parallel to the input field. Or better yet, use a onload
handler to capture the initial values of every fields. Something like:

function saveOriginalVal ues() {
var inputs = document.getEle mentsByTagName( 'INPUT');
for(var i = 0; i < inputs.length; i++) {
var input = inputs[i];
if(input.type == 'text') {
originalValues[input.name] = input.value;
}
}
}

That gives you something that you can reuse across multiple forms.

Mar 22 '06 #6
> As I said in the follow-up, it's easier to store the original value in
a hidden field parallel to the input field. Or better yet, use a onload
handler to capture the initial values of every fields. Something like:


First of all thanks a lot for your solutions.

Yea, I've also thought about your solution (hidden fields). However, I've a
table with hundreds of fields. Today, to sort this table takes already some
time. But if I add for each field a hidden field the sorting will take to
much time. Therefore I try to find a solution to get the real characters (ä,
ö, ü, ...) from the HTML characters (&auml;&ouml;&u uml;, ...).
In the worst case I've to write my own function (search for '&auml;' and
replace it with 'ä', then seach for '&ouml;' and replace it with 'ö', ...)

Stefan
Mar 22 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
17185
by: Barry Olly | last post by:
Hi, I'm working on a mini content management system and need help with dealing with special characters. The input are taken from html form which are then stored into a varchar column in oracle database. When i retrieve the data, some of the special characters have been changed to ??? and also
14
2998
by: Michael Levin | last post by:
I've got the following problem. I'm a biologist and I have a device at work which monitors my frog habitat. The device has a bunch of sensors, and runs an embedded html server with some java functions defined which know how to read the hardware sensorts. I access it from wherever I am via any browser, and it displays the measurements (a set of...
4
8389
by: VK | last post by:
09/30/03 Phil Powell posted his "Radio buttons do not appear checked" question. This question led to a long discussion about the naming rules applying to variables, objects, methods and properties in JavaScript/JScript and HTML/XML elements. Without trying to get famous :-) but thinking it would be interesting to others I decided to post the...
9
2862
by: Robby Bankston | last post by:
I'm working on some code and am running into brick walls. I'm trying to write out Javascript with Javascript and I've read the clj Meta FAQ and didn't see the answer, read many similar posts (with no luck though), and searched through the IRT.ORG Faqs (www.irt.org/script/script.htm). The Javascript is designed to open an popup window and...
3
2670
by: dalei | last post by:
My question is presented more clearly in following web page: http://www.pinyinology.com/signs2.html <html> HTML entities display outside script tags: a&sup1;, a&sup2;, a&sup3;, a⁴ But unicode doesn't display outside script tags: a\xb2, a\xb3, a\u2074
2
28808
by: Barney | last post by:
I have to convert a Java app to .NET, i found and used the conversion tool which converts java to C#, but it only converted about 10% of it, how hard would it be to re-write the java app and keep most of the same logic and could I use alot of the same code? I noticed in the conversion that alot of the java code remained the same, so how close...
3
12944
by: Stefan Mueller | last post by:
Because the characters ', ", ... make troubles in my input boxes I use the following PHP command while generating the page htmlentities($my_var, ENT_QUOTES); However, if I use in my java scripts the string generated by htmlentities it shows ', /&quot;, ... Is there a java script command to change ' to '
1
7683
by: Robert Dodier | last post by:
Hello, Sorry for asking what must be a FAQ, but I wasn't able to find the answer. I have an XML document fragment which I want to store as a text string. I want a function to convert any XML special characters such as < > into the corresponding character entities. I'm working with Java.
11
2762
by: Nathan Sokalski | last post by:
I add several JavaScript events (onchange, onkeypress, etc.) to Controls using the Add method of the Attributes collection. However, if the JavaScript code contains certain characters, such as & or < or several others, it converts them to html, such as &amp; or &lt; which can sometimes cause my scripts not to work. How can I prevent ASP.NET from...
0
7589
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5260
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4886
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3387
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3391
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1810
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
958
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
628
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.